fn main() {
    //example 1
    println!("\r\nExample1 trafficLight!");
    let trafficLight1 = MyTrafficLight::Green{ time:100 };
    if let MyTrafficLight::Green{time} = trafficLight1 {
        println!("MyTrafficLight::Green {} s", time);
    } else {
    }

    //example 2
    println!("\r\nExample2  &[u32] sum");
    let arr = [1,2,3,4,5];
    let arr2 = [u32::MAX,2,3,4,5];
    println!("sum is {:?}", sum(&arr));
    println!("sum is {:?}", sum(&arr2));


    //example 3
    println!("\r\nExample2 get Area for circle/rectangle using trail and tpl");
    let circle = Circle{radius:0.5};
    let rect = Rectangle{width:4.0, height:2.0};
    println!("circle area {}", getArea(&circle));
    println!("rect area {}", getArea(&rect));


}
//example 1//
trait TrafficLight {
    fn time(&self) -> u8;
}

enum MyTrafficLight {
    Red{time: u8},
    Green{time: u8},
    Yellow{time: u8},

}

impl TrafficLight for MyTrafficLight{
    fn time(&self) -> u8 {
        match &self {
            MyTrafficLight::Red {time}    => *time,
            MyTrafficLight::Green {time}  => *time,
            MyTrafficLight::Yellow {time} => *time,
        }
    }
}
//end example 1

//example 2
fn sum(arr: &[u32]) -> Option<u32> {
    let mut result:Option<u32> = Option::Some(0);
    for v in arr.iter() {
        result = result.unwrap().checked_add(*v);
	if let Option::None = result {
            break;
        }
    }
    return result;
}
// end example 2

//example 3
pub trait Area {
    fn getArea(&self) -> f32;
}

struct Circle {
    radius: f32,
}

struct Rectangle {
    width: f32,
    height: f32,
}

impl Area for Circle {
    fn getArea(&self) -> f32 {
        self.radius*self.radius*3.14
    }
}

impl Area for Rectangle {
    fn getArea(&self) -> f32 {
        self.width * self.height
    }
}

pub fn getArea<T:Area>(shape:&T) -> f32 {
    shape.getArea()
}
//end example 3
